package com.crazymo.jni;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.crazymo.jni.bean.Blog;
import com.crazymo.jni.bean.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.appcompat.app.AppCompatActivity;

/**
 * @author cmo
 */
public class ProcessJavaDataActivity extends AppCompatActivity {
    ProcessJavaDataHelper jniHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_process_java_data);
        if (jniHelper == null) {
            jniHelper = new ProcessJavaDataHelper();
        }
    }

    public void sendData(View view) {
        switch (view.getId()) {
            case R.id.btn_send_basic_data:
                jniHelper.sendBasicType(999.9d, 11, 8888L, 8.88f, false, 'M');
                break;
            case R.id.btn_send_strings:
                String strArr[] = {"CrazyMo", "JNI"};
                jniHelper.sendString("hello", strArr);
                break;
            case R.id.btn_send_basic_ref_data:
                jniHelper.sendBasicRefType(Double.valueOf(999.9), new Integer(11), new Long(8888), new Float(8.88), new Boolean(false), new Character('M'));
                break;
            case R.id.btn_send_bean:
                Blog blog = new Blog("csdn.crazymo_", 1008);
                jniHelper.sendBean(blog);
                break;
            case R.id.btn_send_arrays:
                jniHelper.sendArrays(new int[]{88, 99, 66}, new Blog[]{new Blog("Crazy", 9999), new Blog("Mo", 88888)});
                break;
            case R.id.btn_send_list:
                List<String> list = new ArrayList<>();
                list.add("blog.csdn.net");
                list.add("CrazyMo_");
                jniHelper.sendList(list);
                break;
            case R.id.btn_send_map:
                Map<String, String> map = new HashMap<>(4);
                map.put("m", "CrazyMo");
                map.put("mo", "csdn");
                jniHelper.sendMap(map);
                break;
            case R.id.btn_send_java_objs:
                int num = 2020;
                String name = "crazymo_";
                int[] aryy = {2018, 2008, 2020};
                String[] strs = {"CrazyMo_", "https://crazymo.blog.csdn.net/"};
                jniHelper.sendJavaObjs(num, name, aryy, strs);
                break;

            case R.id.btn_get_basic:
                Log.e("CrazyMoJNI", "Received data=" + jniHelper.getBasicData());
                break;
            case R.id.btn_get_strs:
                Log.e("CrazyMoJNI", "Received String =" + jniHelper.getStringData());
                break;
            case R.id.btn_get_int_array:
                Log.e("CrazyMoJNI", "Received Int Array =" + jniHelper.getIntArrayData(8));
                break;
            case R.id.btn_get_list:
                Log.e("CrazyMoJNI", "Received List=" + jniHelper.getListData(2));
                break;
            case R.id.btn_get_map:
                Log.e("CrazyMoJNI", "Received Map=" + jniHelper.getMapData(2));
                break;
            case R.id.btn_upd_user:
                User user = new User();
                user.name = "crazy";
                user.no = 666666;
                Log.e("CrazyJava", "经native 更新前：" + Thread.currentThread().getId() + "name=" + user.name + "\tno=" + user.no);
                jniHelper.updateUser(user);
                Log.e("CrazyJava", "经native 更新后：" + Thread.currentThread().getId() + "name=" + user.name + "\tno=" + user.no);
                break;
            default:
                break;
        }
    }
}